const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
console.log('context', process.cwd().replace(/\\/g, '/'));
module.exports = {
    mode: 'development',
    entry: './src/index.js',
    devtool: false,
    //指定当前的根目录
    context: process.cwd().replace(/\\/g, '/'), 
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'main.js'
    },
    //在webpack解析loader的时候配置如何查找
    resolveLoader: {
        //配置别名
        alias: {
            'inline1-loader': path.resolve(__dirname, 'loaders', 'inline1-loader.js'),
            'inline2-loader': path.resolve(__dirname, 'loaders', 'inline2-loader.js'),
            'babel-loader': path.resolve(__dirname, 'loaders', 'babel-loader')
        },
        //配置去哪些目录里找loader 
        modules: ['node_modules', path.resolve(__dirname, 'loaders')]
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                use: {
                    loader: 'babel-loader',//别名
                    options: {
                        presets: ["@babel/preset-env"],
                        plugins: []
                    }
                }
            },
            /**
             * 先走style-loader的pitch函数，拿到返回值后交给webpack，
             * webpack处理返回值，通过内联loader使用less-laoder处理index.less，将处理的结果放到依赖关系中
             * 等待打包结果中的调用
             * 
             */
            {
                test: /\.less$/,
                // 配置两个loader
                use: ['style-loader', 'less-loader']
                
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './public/index.html'
        })
    ]
}